<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		
		<script type="text/javascript">
			
			function Person(name,age,gender){
					this.name=name;
					this.age=age;
					this.gender=gender;
			}
			
			Person.prototype.toString=function(){
				return "Person[name="+this.name+",age="+this.age+",gender="+this.gender+"]";
			};
			
			//创建对象
			var per1=new Person("红孩儿",8,"男");
			var per2=new Person("牛魔王",32,"男");
			var per3=new Person("孙悟空",18,"男");
			var per4=new Person("铁扇公主",28,"男");
			
			//console.log(per1);
			
			//创建数组存储对象
			var perArr=[per1,per2,per3,per4];
			
	
			//创建函数
			function getAdult(arr){
				//创建新数组
				var newArr=[];
				//遍历输入数组
				for (var i = 0; i < arr.length; i++) {
					
					//p接收数组的每个元素；
					var p=arr[i];
					//console.log(p);
					
					//判断数组年龄
					if(p.age>=18){
						
						//将满足的元素添加到newArr中；
						newArr.push(p);
				
					}
				}
				//函数返回值为新的数组
				return newArr;
			}
			
			//声明result接收调用函数后得到的返回值；
			var result=getAdult(perArr);
			//打印result；
			console.log(result);
			
			
		</script>
	</head>
	<body>
	</body>
</html>
